#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>

int main(int argc, char *argv[])
{
    int sockfd;
    if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
    {
        perror("error:");
        exit(1);
    }

    struct sockaddr_in sockaddr;
    sockaddr.sin_family = AF_INET;
    sockaddr.sin_addr.s_addr = inet_addr("10.65.212.250");
    sockaddr.sin_port = htons(8080);

    if(bind(sockfd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == -1)
    {
        perror("error: bind");
        exit(1);
    }

    while(1)
    {
    char buf[128];
    struct sockaddr_in cliaddr;

    socklen_t addrlen = sizeof(struct sockaddr_in);
    if(recvfrom(sockfd, buf, 128, 0, (struct sockaddr*)&cliaddr, &addrlen) == -1)
    {
        perror("error: recvfrom");
        exit(1);
    }

    printf("ip:%s, port:%d\n", inet_ntoa(cliaddr.sin_addr), ntohs(cliaddr.sin_port));
    printf("messgae:%s\n", buf);

    }
    return 0;
}